package practice01;
import java.util.Scanner;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: practice01
 * @ClassName: GuessMachine
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/2 18:18
 * @Copyright 大牛版板所有
 */
public class GuessMachine {
    Television[] tvs = new Television[3];
    int num;

    public void initial(int randomNum){
        tvs[0] = new Television("小米电视",3399.0);
        tvs[1] = new Television("LG电视",5999.0);
        tvs[2] = new Television("海尔电视",12999.0);
        num = randomNum;
    }
    public boolean guess(double guessPrice){
        if (tvs[num].price == guessPrice){
            System.out.println("恭喜您，猜对了！");
            return true;
        }
        else if (tvs[num].price < guessPrice){
            System.out.println("再小一些!");
        }
        else {
            System.out.println("再大一些!");
        }
        return false;
    }
    public static void main(String[] args) {
        GuessMachine guess = new GuessMachine();
        int num = (int) (Math.random()*3);
        System.out.println(num);
        guess.initial(num);
        Scanner input = new Scanner(System.in);
        for (int i = 0;; i++) {
            if (i > 2){
                System.out.println("最多猜3次，本次游戏结束，下次继续努力！");
                break;
            }
            System.out.print("请输入你猜的商品价格：");
            double guessPr = input.nextDouble();
            if (guess.guess(guessPr)){
                break;
            }
        }
    }
}
